package br.com.gtoolz.myimc.db;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = "myimc.db";
	private static final int DATABASE_VERSION = 1;
	private static final String TABLE1 = "imcs";
	private static final String TABLE2 = "cals";

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		String sql1 = "CREATE TABLE IF NOT EXISTS " + TABLE1 + " (id INTEGER PRIMARY KEY AUTOINCREMENT," +
				" data TEXT, imc TEXT, status TEXT)";
		db.execSQL(sql1);
		
		String sql2 = "CREATE TABLE IF NOT EXISTS " + TABLE2 + " (id INTEGER PRIMARY KEY AUTOINCREMENT," +
				" data TEXT, tmb TEXT, qna TEXT, qcp TEXT, qcg TEXT, descricao TEXT)";
		db.execSQL(sql2);
	
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if ((newVersion - oldVersion) > 2) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE1);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE2);
            onCreate(db);
        }  		
	}
	
}